<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <h1>串料执行</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" class="form-inline">
                        <div class="form-group">
                            <label>
                                单据编号
                            </label>
                            <input name="ceoCode" type="text" class="form-control text" maxlength="50"
                                   placeholder="请输入单据编号"/>
                        </div>
                        <div class="form-group">
                            <label>
                                需求项目编号
                            </label>
                            <input name="ceoNeedProCode" type="text" class="form-control text"
                                   placeholder="请输入项目编号"/>
                        </div>
                        <div class="form-group">
                            <label>
                                需求项目名称
                            </label>
                            <input name="ceoNeedProName" type="text" class="form-control text" maxlength="255"
                                   placeholder="请输入项目名称"/>
                        </div>

                        <div class="form-group">
                            <label>
                                申请人
                            </label>
                            <input name="ceoAppPerson" type="text" class="form-control text" maxlength="255"
                                   placeholder="请输入申请人信息"/>
                        </div>
                        <div class="form-group">
                            <label>
                                使用部门
                            </label>
                            <input name="ceoNeedDepName" class="form-control ">
                        </div>
                        <div class="form-group">
                            <label>
                                串料申请单状态
                            </label>
                            <select name="ceoAppyStatus" class="form-control select">
                                <option value="">全部</option>
                                <option value="2">未执行</option>
                                <option value="3">已执行</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label>申请日期</label>
                            <input type="text" class="form-control datepicker" id="startOdrMakeDate"
                                   name="startOdrMakeDate" readonly="readonly"/>
                            <span>至</span>
                            <input type="text" class="form-control datepicker" id="endOdrMakeDate"
                                   name="endOdrMakeDate" readonly="readonly"/>
                        </div>
                        <div class="form-group">
                            <button type="button" class="btn btn-success" id="btn-search">搜索
                            </button>
                        </div>
                    </form>
                </div>
                <div id="toolbar">
                    <button type="button" class="btn btn-success" onclick="execApply('')">
                        批量执行
                    </button>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table" class="table table-bordered " width="100%">
                    </table>
                </div>
            </div>
        </div>
    </div>
</section>

<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var table;
    var ceoAppyStatusText = ["", "未提交", "未执行", "已执行", "被驳回"];
    var colors = ['', "bg-gray", "bg-gray", "bg-green", "bg-red"];

    function revokeApply(ceoIds) {
        js.modal.confirm("您确认要撤销此标记吗？", function () {

            $.post(ctx + 'half/halInvManage/changeExc/revokeApply', {
                ceoIds: ceoIds
            }, function (result) {
                if (result.type == "SUCCESS") {
                    js.table.refresh(table);
                } else if (result.type == "ERROR") {
                    js.modal.fail(result.msg);
                }
            }, 'json');
        });
    }


    /**
     *@FunctionName: execApply
     *@Description: 执行
     *@Author: TH
     *@Version: 1.0.0
     */
    function execApply(ceoIds) {
        js.modal.confirm("您确认要执行此标记吗？", function () {
            if (ceoIds == '') {
                $('input[name="cb_change"]').each(function () {
                    if (!$(this).prop("disabled")) {
                        if ($(this).prop("checked")) {
                            ceoIds += $(this).attr("data") + ",";
                        }
                    }
                })
                ceoIds = ceoIds.substring(0, ceoIds.length - 1);
            }
            if (ceoIds == '') {
                js.modal.warning("请选择要执行的串料申请！");
                return;
            }
            $.post(ctx + 'half/halInvManage/changeExc/execApply', {
                ceoIds: ceoIds
            }, function (result) {
                if (result.type == "SUCCESS") {
                    js.table.refresh(table);
                    js.modal.success(result.msg)
                }
                if (result.type == "ERROR") {
                    js.modal.success(result.msg)
                }
            }, 'json');
        });
    }
        /*js.modal.confirm("您确认要执行此标记吗？", function () {
            $.post(ctx + 'half/halInvManage/changeExc/execApply', {
                ceoIds: ceoIds
            }, function (result) {
                if (result.type == "SUCCESS") {
                    js.table.refresh(table);
                    js.modal.success(result.msg)
                }
                if (result.type == "ERROR") {
                    js.modal.success(result.msg)
                }
            }, 'json');
        });
    }*/

    /**
     *@FunctionName: removeAppy
     *@Description: 驳回
     *@Author: TH
     *@Version: 1.0.0
     */
    function removeApply(ceoIds) {
        js.modal.confirm("您确认要驳回此标记吗？", function () {
            if (ceoIds == '') {
                $('input[name="cb_change"]').each(function () {
                    if (!$(this).prop("disabled")) {
                        if ($(this).prop("checked")) {
                            ceoIds += $(this).attr("data") + ",";
                        }
                    }
                })
                ceoIds = ceoIds.substring(0, ceoIds.length - 1);
            }
            if (ceoIds == '') {
                js.modal.warning("请选择要驳回的串料申请！");
                return;
            }
            $.post(ctx + 'half/halInvManage/changeExc/remove', {
                ceoIds: ceoIds
            }, function (result) {
                if (result.type == "SUCCESS") {
                    $("#selectAll").prop('checked', false);
                    js.table.refresh(table);
                }
            }, 'json');
        });
    }



    /**
     *@FunctionName: search
     *@Description: 查询
     *@Author: TH
     *@Version: 1.0.0
     */
    function search() {
        js.table.search(table);
    }

    /**
     *@FunctionName: selectAll
     *@Description: 全选
     *@Author: TH
     *@Version: 1.0.0
     */
    function selectAll(obj) {
        $('input[name="cb_change"]').each(function () {
            if (!$(this).prop("disabled")) {
                if ($(obj).prop("checked")) {
                    $(this).prop("checked", true);
                }
                if ($(obj).prop("checked") == false) {
                    $(this).prop("checked", false);
                }
            }
        })
    }

    $(function () {
        //加载列表数据
        table = js.table.init({
            id: 'bootstrap-table',
            url: ctx + "half/halInvManage/changeExc/list",
            showColumns: true,
            showExport: false,
            pageSize: 300,
            striped: false,
            uniqueId: "rppId",
            onLoadSuccess: function () {
                $('#inventoryQueryTable thead th').each(function () {
                    $(this).width(Math.floor($(this).width()));
                });
                $('#inventoryQueryTable tbody tr:first td').each(function () {
                    $(this).width(Math.floor($(this).width()));
                });
            },
            columns: [
                {
                    title: '<input title="全选" id="selectAll" onclick="selectAll(this)" type="checkbox" />',
                    width: '30',
                    field: 'ceoId',
                    formatter: function (value, row, index) {
                        var disabled = 'disabled="disabled"';
                        if (row.ceoAppyStatus != undefined && row.ceoAppyStatus != null && row.ceoAppyStatus == 2) {
                            disabled = "";
                        }
                        return '<input  style="width: 30px;height: 30px" ' + disabled + ' id="cb_change' + row.ceoId + '" name="cb_change" data="' + row.ceoId + '"  type="checkbox" />';
                    }
                },
                {
                    title: '序号', field: 'ceoId', width: '40',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: '单据编号', field: 'ceoCode'},
                {title: '需求<br>项目号', field: 'ceoNeedProCode'},
                {title: '需求<br>项目名称', field: 'ceoNeedProName'},
                {title: '需求<br>物料描述', field: 'ceoNeedMatName'},
                {title: '需求<br>数量', field: 'ceoNeedNum'},
                {title: '使用部门', field: 'ceoNeedDepName'},
                {
                    title: '挪用<br>项目编号', field: 'ceoUseProCode'
                    , formatter: function (value, row, index) {
                        if (value == undefined) {
                            return "";
                        }
                        return value;
                    }
                },
                {
                    title: '挪用<br>项目名称', field: 'ceoUseProName'
                    , formatter: function (value, row, index) {
                        if (value == undefined) {
                            return "";
                        }
                        return value;
                    }
                },
                {
                    title: '挪用<br>物料描述', field: 'ceoUseMatName'
                    , formatter: function (value, row, index) {
                        if (value == undefined) {
                            return "";
                        }
                        return value;
                    }
                },
                {
                    title: '申请日期', field: 'ceoAppDate',width:'90'
                    , formatter: function (value, row, index) {
                        if (value == undefined) {
                            return "";
                        }
                        return value;
                    }
                },
                {
                    title: '申请人', field: 'ceoAppPerson'
                    , formatter: function (value, row, index) {
                        if (value == undefined) {
                            return "";
                        }
                        return value;
                    }
                },
                {
                    title: '状态', field: 'ceoAppyStatus'
                    , formatter: function (value, row, index) {
                        if (value == undefined) {
                            return "";
                        }
                        return '<span class="badge ' + colors[value] + '">' + ceoAppyStatusText[value] + '</span> ';
                    }
                },
                {
                    title: '操作', field: 'ceoId', width: '140',
                    formatter: function (value, row, index) {
                        var htmlText = "";
                        if ((row.ceoAppyStatus == 1 || row.ceoAppyStatus == 2 || row.ceoAppyStatus == 3 || row.ceoAppyStatus == 4 || row.ceoAppyStatus == 5) && hasP("halinv:halexeccha:view")) {
                            htmlText += '<button class="btn btn-info btn-xs" onclick="seePanel(' + row.ceoId + ')">查看</button>';
                        }
                        if (row.ceoAppyStatus == 3 && hasP("halinv:halexeccha:edit")) {
                            htmlText += '<button class="btn btn-primary btn-xs" onclick="revokeApply(' + row.ceoId + ')">撤销</button>';
                        }
                        if (row.ceoAppyStatus == 2 && hasP("halinv:halexeccha:edit")) {
                            htmlText += '<button class="btn btn-success btn-xs"  onclick="execApply(' + row.ceoId + ')">执行</button>';
                        }
                        if (row.ceoAppyStatus == 2 && hasP("halinv:halexeccha:edit")) {
                            htmlText += '<button onclick="removeApply(' + row.ceoId + ')" class="btn btn-xs btn-danger">驳回</button>';
                        }
                        return htmlText;
                    }
                }
            ]
        });
        /**
         * 表格搜索
         */
        $("#btn-search").on('click', function () {
            js.table.search(table);
        });
    });

    /**
     *@FunctionName: seePanel
     *@Description: 查看
     *@Author: TH
     *@Version: 1.0.0
     */
    function seePanel(ceoId) {
        location.href = "viewPage/see/" + ceoId;
    }
</script>
</body>
</html>
